from datetime import datetime
from typing import Optional, List
from pydantic import BaseModel


class CreateArticleRequest(BaseModel):
    created_on: Optional[datetime] = None
    created_by: Optional[int] = None
    title: str
    abstract: Optional[str] = None
    content: str
    tags: Optional[List[str]] = []
    author: Optional[str] = None
    avatar: Optional[str] = None
    cover: Optional[str] = None


class ArticleModel(BaseModel):
    id: int
    created_on: Optional[datetime] = None
    created_by: Optional[int] = None
    updated_on: Optional[datetime] = None
    updated_by: Optional[int] = None
    status: Optional[int] = 1
    title: str
    abstract: Optional[str] = None
    content: str
    tags: Optional[List[str]] = []
    author: Optional[str] = None
    avatar: Optional[str] = None
    cover: Optional[str] = None
    views_count: Optional[int] = 1
    likes_count: Optional[int] = 1
    comments_count: Optional[int] = 0

    class Config:
        from_attributes = True


class UpdateArticleRequest(CreateArticleRequest):
    id: int
    updated_on: Optional[datetime] = None
    updated_by: Optional[int] = None


class ArticlePagination(BaseModel):
    page: int
    page_size: int
    total: int
    data: List[ArticleModel]


class DeleteArticleRequest(BaseModel):
    id: int
    updated_on: Optional[datetime] = None
    updated_by: Optional[int] = None


class CreateArticleCommentRequest(BaseModel):
    article_id: int
    customer_id: Optional[int] = None
    parent_id: Optional[int] = None
    content: str


class ArticleCommentItem(BaseModel):
    id: int
    customer_id: int
    parent_id: Optional[int] = None
    likes_count: Optional[int] = 0
    avatar: Optional[str] = None
    nickname: str
    content: str
    created_on: datetime


class LikeArticleCommentRequest(BaseModel):
    customer_id: Optional[int] = None
    comment_id: int
    is_like: Optional[bool] = True


class LikeArticleRequest(BaseModel):
    customer_id: Optional[int] = None
    article_id: int
    is_like: Optional[bool] = True
